home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / what's new? / sample code / graphics 3d / setupgl / error handler.c next >
Encoding:
Text File  |  1999-12-18  |  6.4 KB  |  199 lines

  1. /*
  2.     File:        Error Handler.c
  3.  
  4.     Contains:    SetupGL error handling
  5.  
  6.     Written by:    Geoff Stahl (ggs)
  7.  
  8.     Copyright:    Copyright © 1999 Apple Computer, Inc., All Rights Reserved
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>    12/18/99    ggs     Fix headers
  13.          <2>    11/28/99    ggs     Added verbose error flag
  14.          <1>    11/28/99    ggs     Initial add.  Split of just error handling functions.  Need to
  15.                                     add more reporting examples
  16.          <1>    11/11/99    ggs     Initial Add
  17.  
  18.     Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  19.                 ("Apple") in consideration of your agreement to the following terms, and your
  20.                 use, installation, modification or redistribution of this Apple software
  21.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  22.                 please do not use, install, modify or redistribute this Apple software.
  23.  
  24.                 In consideration of your agreement to abide by the following terms, and subject
  25.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  26.                 copyrights in this original Apple software (the "Apple Software"), to use,
  27.                 reproduce, modify and redistribute the Apple Software, with or without
  28.                 modifications, in source and/or binary forms; provided that if you redistribute
  29.                 the Apple Software in its entirety and without modifications, you must retain
  30.                 this notice and the following text and disclaimers in all such redistributions of
  31.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  32.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  33.                 Apple Software without specific prior written permission from Apple.  Except as
  34.                 expressly stated in this notice, no other rights or licenses, express or implied,
  35.                 are granted by Apple herein, including but not limited to any patent rights that
  36.                 may be infringed by your derivative works or by other works in which the Apple
  37.                 Software may be incorporated.
  38.  
  39.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  40.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  41.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  42.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  43.                 COMBINATION WITH YOUR PRODUCTS.
  44.  
  45.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  46.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  47.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  49.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  50.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  51.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. */
  53.  
  54. //#define kVerboseErrors
  55. //#define kQuake3
  56.  
  57. // system includes ----------------------------------------------------------
  58.  
  59. #ifdef kQuake3
  60. typedef int sysEventType_t;    // FIXME...
  61. #endif
  62.  
  63. #include <MacTypes.h>
  64.  
  65. #include <stdio.h>
  66.  
  67.  
  68. // project includes ---------------------------------------------------------
  69.  
  70. #include "Error Handler.h"
  71.  
  72. #ifdef kQuake3
  73. #include "../renderer/tr_local.h"
  74. #include "mac_local.h"
  75. #endif
  76.  
  77.  
  78. // globals (internal/private) -----------------------------------------------
  79.  
  80.  
  81. // prototypes (internal/private) --------------------------------------------
  82.  
  83. void CStrToPStr (StringPtr outString, const char *inString);
  84.  
  85.  
  86. // functions (internal/private) ---------------------------------------------
  87.  
  88. // Copy C string to Pascal string
  89.  
  90. void CStrToPStr (StringPtr outString, const char *inString)
  91. {    
  92.     unsigned char x = 0;
  93.     do
  94.         *(((char*)outString) + x) = *(inString + x++);
  95.     while ((*(inString + x) != 0)  && (x < 256));
  96.     *((char*)outString) = (char) x;                                    
  97. }
  98.  
  99. #pragma mark -
  100. // --------------------------------------------------------------------------
  101.  
  102. // central error reporting
  103.  
  104. void ReportErrorNum (char * strError, long numError)
  105. {
  106.     char errMsgCStr [256];
  107.     Str255 strErr = "\p";
  108.     
  109.     sprintf (errMsgCStr, "%s %d\n", strError, numError); 
  110.  
  111.     // out as debug string
  112. #ifdef kVerboseErrors
  113.     #ifdef kQuake3
  114.         ri.Printf( PRINT_ALL, errMsgCStr);
  115.     #else
  116.             CStrToPStr (strErr, errMsgCStr);
  117.             DebugStr (strErr);
  118.     #endif // kQuake3
  119. #endif // kVerboseErrors
  120. }
  121.  
  122. // --------------------------------------------------------------------------
  123.  
  124. void ReportError (char * strError)
  125. {
  126.     char errMsgCStr [256];
  127.     Str255 strErr = "\p";
  128.  
  129.     sprintf (errMsgCStr, "%s\n", strError); 
  130.  
  131.     // out as debug string
  132. #ifdef kVerboseErrors
  133.     #ifdef kQuake3
  134.         ri.Printf( PRINT_ALL, errMsgCStr);
  135.     #else
  136.             CStrToPStr (strErr, errMsgCStr);
  137.             DebugStr (strErr);
  138.     #endif //  kQuake3
  139. #endif // kVerboseErrors
  140. }
  141.  
  142. //-----------------------------------------------------------------------------------------------------------------------
  143.  
  144. OSStatus DSpReportError (OSStatus error)
  145. {
  146.     switch (error)
  147.     {
  148.         case noErr:
  149.             break;
  150.         case kDSpNotInitializedErr:
  151.             ReportError ("DSp Error: Not initialized");
  152.             break;
  153.         case kDSpSystemSWTooOldErr:
  154.             ReportError ("DSp Error: system Software too old");
  155.             break;
  156.         case kDSpInvalidContextErr:
  157.             ReportError ("DSp Error: Invalid context");
  158.             break;
  159.         case kDSpInvalidAttributesErr:
  160.             ReportError ("DSp Error: Invalid attributes");
  161.             break;
  162.         case kDSpContextAlreadyReservedErr:
  163.             ReportError ("DSp Error: Context already reserved");
  164.             break;
  165.         case kDSpContextNotReservedErr:
  166.             ReportError ("DSp Error: Context not reserved");
  167.             break;
  168.         case kDSpContextNotFoundErr:
  169.             ReportError ("DSp Error: Context not found");
  170.             break;
  171.         case kDSpFrameRateNotReadyErr:
  172.             ReportError ("DSp Error: Frame rate not ready");
  173.             break;
  174.         case kDSpConfirmSwitchWarning:
  175. //            ReportError ("DSp Warning: Must confirm switch"); // removed since it is just a warning, add back for debugging
  176.             return 0; // don't want to fail on this warning
  177.             break;
  178.         case kDSpInternalErr:
  179.             ReportError ("DSp Error: Internal error");
  180.             break;
  181.         case kDSpStereoContextErr:
  182.             ReportError ("DSp Error: Stereo context");
  183.             break;
  184.     }
  185.     return error;
  186. }
  187.  
  188. //-----------------------------------------------------------------------------------------------------------------------
  189.  
  190. // if error dump agl errors to debugger string, return error
  191.  
  192. GLenum aglReportError (void)
  193. {
  194.     GLenum err = aglGetError();
  195.     if (AGL_NO_ERROR != err)
  196.         ReportError ((char *)aglErrorString(err));
  197.     return err;
  198. }
  199.